<template>
	<xn-form-container :title="reason" :width="500" :visible="visible" :destroy-on-close="true" @close="onClose">
		<a-form ref="formRef" :model="formData" layout="vertical">
			<a-form-item label="请输入退回理由：" name="reason">
				<a-input v-model:value="formData.reason" placeholder="请输入退回理由" allow-clear />
			</a-form-item>
		</a-form>
		<template #footer>
			<a-button style="margin-right: 8px" @click="onClose">关闭</a-button>
			<a-button type="primary" @click="onSubmit" :loading="submitLoading">保存</a-button>
		</template>
	</xn-form-container>
</template>

<script setup>
	// 默认是关闭状态
	import amsItemPickupRecordApi from '@/api/ams/pickUp/amsItemPickupRecordApi'

	const formRef = ref({})
	const submitLoading = ref(false)
	// 表单数据
	const formData = ref({
		reason: '',
		id: ''
	})
	const visible = ref(false)
	const emit = defineEmits({ successful: null })
	const reason = ref('退回原因')
	// 打开抽屉
	const onOpen = (record) => {
		visible.value = true
		console.log(record.id)
		formData.value.id = record.id
	}
	// 提交表单
	const onSubmit = async () => {
		await amsItemPickupRecordApi.returnAmsItemPickupRecord(formData.value)
		onClose()
		emit('successful')
	}
	// 关闭抽屉
	const onClose = () => {
		visible.value = false
	}
	// 调用这个函数将子组件的一些数据和方法暴露出去
	defineExpose({
		onOpen
	})
</script>
